package com.itheima.mapper;

import com.itheima.pojo.OrderSetting;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface OrderSettingMapper {
    /**
     * 根据日期范围查询预约设置信息
     * @param firstDay
     * @param lastDay
     * @return
     */
    @Select(("select * from order_setting where order_date >= #{firstDay} and order_date <= #{lastDay}"))
    List<OrderSetting> selectByField(LocalDate firstDay, LocalDate lastDay);

    /**
     * 根据日期修改预约设置信息-可预约数
     * @param orderSetting
     * @return
     */
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Update("update order_setting set number = #{number} where order_date = #{orderDate}")
    Integer updateByDate(OrderSetting orderSetting);

    /**
     * 根据日期修改预约设置信息-预约人数
     * @param orderSetting
     * @return
     */
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Update("update order_setting set reservations = #{reservations} where order_date = #{orderDate}")
    Integer updateReservationByDate(OrderSetting orderSetting);

    /**
     * 根据日期查询预约设置信息
     * @param orderDate
     * @return
     */
    @Select("select * from order_setting where order_date = #{orderDate}")
    OrderSetting selectByDay(LocalDate orderDate);

    /**
     * 添加预约设置信息
     * @param orderSetting
     * @return
     */
    @Insert("insert into order_setting(order_date, number, reservations) values(#{orderDate}, #{number}, #{reservations})")
    Integer insert(OrderSetting orderSetting);
}
